<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>libdill</title>
  <link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>

<h1>libdill: Structured Concurrency for C</h1>

<ul id='toplist'>
<li><a href="index.html">Home</a></li>
<li><a href="download.html">Download</a></li>
<li><a href="documentation.html">Documentation</a></li>
<li><a href="tutorial.html">Tutorials</a></li>
<li><a href="faq.html">FAQ</a></li>
</ul>
<h1 id="name">NAME</h1>
<p>udp_send - sends an UDP packet</p>
<h1 id="synopsis">SYNOPSIS</h1>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="pp">#include </span><span class="im">&lt;libdill.h&gt;</span>

<span class="dt">int</span> udp_send(
    <span class="dt">int</span> s,
    <span class="dt">const</span> <span class="kw">struct</span> ipaddr* addr,
    <span class="dt">const</span> <span class="dt">void</span>* buf,
    <span class="dt">size_t</span> len);</code></pre></div>
<h1 id="description">DESCRIPTION</h1>
<p>UDP is an unreliable message-based protocol defined in RFC 768. The size of the message is limited. The protocol has no initial or terminal handshake. A single socket can be used to different destinations.</p>
<p>This function sends an UDP packet.</p>
<p>Given that UDP protocol is unreliable the function has no deadline. If packet cannot be sent it will be silently dropped.</p>
<p><strong>s</strong>: Handle of the UDP socket.</p>
<p><strong>addr</strong>: IP address to send the packet to. If set to <strong>NULL</strong> remote address specified in <strong>udp_open</strong> function will be used.</p>
<p><strong>buf</strong>: Data to send.</p>
<p><strong>len</strong>: Number of bytes to send.</p>
<p>This function is not available if libdill is compiled with <strong>--disable-sockets</strong> option.</p>
<h1 id="return-value">RETURN VALUE</h1>
<p>In case of success the function returns 0. In case of error it returns -1 and sets <strong>errno</strong> to one of the values below.</p>
<h1 id="errors">ERRORS</h1>
<ul>
<li><strong>EBADF</strong>: Invalid handle.</li>
<li><strong>EINVAL</strong>: Invalid argument.</li>
<li><strong>EMSGSIZE</strong>: The message is too long to fit into an UDP packet.</li>
<li><strong>ENOTSUP</strong>: The handle does not support this operation.</li>
</ul>
<h1 id="example">EXAMPLE</h1>
<div class="sourceCode"><pre class="sourceCode c"><code class="sourceCode c"><span class="kw">struct</span> ipaddr local;
ipaddr_local(&amp;local, NULL, <span class="dv">5555</span>, <span class="dv">0</span>);
<span class="kw">struct</span> ipaddr remote;
ipaddr_remote(&amp;remote, <span class="st">&quot;server.example.org&quot;</span>, <span class="dv">5555</span>, <span class="dv">0</span>, <span class="dv">-1</span>);
<span class="dt">int</span> s = udp_open(&amp;local, &amp;remote);
udp_send(s1, NULL, <span class="st">&quot;ABC&quot;</span>, <span class="dv">3</span>);
<span class="dt">char</span> buf[<span class="dv">2000</span>];
<span class="dt">ssize_t</span> sz = udp_recv(s, NULL, buf, <span class="kw">sizeof</span>(buf), <span class="dv">-1</span>);
hclose(s);</code></pre></div>
<h1 id="see-also">SEE ALSO</h1>
<p><strong>mrecv</strong>(3) <strong>mrecvl</strong>(3) <strong>msend</strong>(3) <strong>msendl</strong>(3) <strong>udp_open</strong>(3) <strong>udp_open_mem</strong>(3) <strong>udp_recv</strong>(3) <strong>udp_recvl</strong>(3) <strong>udp_sendl</strong>(3)</p>
</body>
